package com.xpgk.mvc.bsendMessage;

import java.util.ArrayList;
import java.util.List;

import com.jfinal.plugin.activerecord.Record;



public class RecordKit {

	public static String getToList_List(Record rs, String column){
		if(rs == null){
			return "";
		}
		StringBuffer stringBuffer = new StringBuffer();
		String[] str = column.split(",");
		for(int i=0;i<str.length;i++){
			if(str[i].equals("status")){
				stringBuffer.append(1);
			}else{
				stringBuffer.append(rs.get(str[i]));
			}
			if(i != str.length-1){
				stringBuffer.append(",");
			}
		}
		return stringBuffer.toString();
	}
	
	

	@SuppressWarnings("unchecked")
	public static <T> List<T> getToList(List<Record> rs, String column, Class<T> clazz) 
	{
		if(rs == null || rs.isEmpty())
		{
			return new ArrayList<T>();
		}
		
		List<T> list = new ArrayList<T>();
		for (Record r : rs) {
			if(r.get(column) != null){
				list.add((T)(r.get(column)));
			}else{
				list.add((T)(Integer)0);
			}
			
		}
		
		return list;
	}

	public static List<Record> putHHmm(List<Record> list, String column, String newColumn) 
	{
		if(list == null || list.isEmpty())
		{
			return new ArrayList<Record>();
		}
		for (Record record : list) 
		{
			int millSeconds = record.getInt(column);
			record.set(newColumn, DateUtil.toHHmm(millSeconds*1000));
		}
		return list;
	}

}
